package com.tanhua.manage.exception;

import com.tanhua.manage.vo.CommonResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.HashMap;
import java.util.Map;

// 是一个统一异常处理器，controller主要抛出了异常都会触发这个类的某个方法去处理异常
@ControllerAdvice
public class ExceptionAdvice {


    @ExceptionHandler(value = Exception.class)
    public ResponseEntity handlExcpetion(Exception e){
        e.printStackTrace();
        CommonResponse commonResponse = new CommonResponse(e.getMessage());
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(commonResponse);
    }
}
